<!--title-->
<div class="mnav1">
	<div class="m_nav">
		<div class="nav_left">
			<em class="home_icon"><?=$this->sys_name?></em><span>&nbsp;&gt;&nbsp;</span><font><?=$this->title?></font>
		</div>
	</div>
</div>

<div class="content-table">
<div class="content-table-title"><?=$this->title?></div>
<br />
<?php if($this->msg):?>
<div class="replace"><?=$this->msg?></div>
<br />
<?php endif;?>
<form action="/contracts/index" name="form1" method="GET">
<?php if("LEVEL-1" != $_SESSION['identity']['level']):?>
销售：<select name="sales_emp_id">
		<option value="">不限</option>
		<?php if(!empty($this->sales)):?>
		<?php foreach($this->sales as $sales_emp_id => $sales_name):?>
		<option value="<?=$sales_emp_id?>"><?=$sales_name?></option>
		<?php endforeach;?>
		<?php endif;?>
	</select>
&nbsp;&nbsp;&nbsp;&nbsp;
<?php endif;?>
产品：<select name="product_id">
		<option value="">不限</option>
		<?php if(!empty($this->products)):?>
		<?php foreach($this->products as $product_id => $product_name):?>
		<option value="<?=$product_id?>"><?=$product_name?></option>
		<?php endforeach;?>
		<?php endif;?>
	</select>
&nbsp;&nbsp;&nbsp;&nbsp;
乙方单位：<select name="owner_id">
		<option value="">不限</option>
		<?php if(!empty($this->owners)):?>
		<?php foreach($this->owners as $owner_id => $owner_name):?>
		<option value="<?=$owner_id?>"><?=$owner_name?></option>
		<?php endforeach;?>
		<?php endif;?>
	</select>
&nbsp;&nbsp;&nbsp;&nbsp;
经销商类型：<select name="dealer_type">
		<option value="">不限</option>
		<option value="1">4S</option>
		<option value="2">展厅</option>
		<option value="3">综合店</option>
	</select>
&nbsp;&nbsp;&nbsp;&nbsp;
签约性质：<select name="contract_type">
		<option value="">不限</option>
		<option value="1">新签</option>
		<option value="2">续签</option>
	</select>
&nbsp;&nbsp;&nbsp;&nbsp;
续签性质：<select name="renew_type">
		<option value="">不限</option>
		<option value="1">30天内续签</option>
		<option value="2">到期未续</option>
		<option value="3">未到期</option>
	</select>
&nbsp;&nbsp;&nbsp;&nbsp;
省：<select name="provinceId" id="provinceId" onchange="GetCities(this.options[this.options.selectedIndex].value);">
	<option value="">不限</option>
	<?php if(!empty($this->provinces)):?>
	<?php foreach($this->provinces as $provinceId => $provinceName):?>
	<option value="<?=$provinceId?>" <?php if($provinceId==$this->provinceId){echo "selected='selected'";}?>><?=$provinceName?></option>
	<?php endforeach;?>
	<?php endif;?>
</select>
&nbsp;&nbsp;
市：<select name="cityId" id="cityId">
		<option value="">不限</option>
		<?php if(!empty($this->init_cities)):?>
		<?php foreach($this->init_cities as $init_cities):?>
		<option value="<?=$init_cities['cityId']?>" <?php if($init_cities['cityId']==$this->cityId){echo "selected='selected'";}?>><?=$init_cities['cityName']?></option>
		<?php endforeach;?>
		<?php endif;?>
	</select>
<br>
签约开始时间：<input type="text" name="contract_start_date_start" id="contract_start_date_start" style="width: 100px"> ~ <input type="text" name="contract_start_date_end" id="contract_start_date_end" style="width: 100px">&nbsp;&nbsp;&nbsp;&nbsp;
签约结束时间：<input type="text" name="contract_expired_date_start" id="contract_expired_date_start" style="width: 100px"> ~ <input type="text" name="contract_expired_date_end" id="contract_expired_date_end" style="width: 100px">
<br />
服务开始时间：<input type="text" name="service_start_date_start" id="service_start_date_start" style="width: 100px"> ~ <input type="text" name="service_start_date_end" id="service_start_date_end" style="width: 100px">&nbsp;&nbsp;&nbsp;&nbsp;
服务结束时间：<input type="text" name="service_expired_date_start" id="service_expired_date_start" style="width: 100px"> ~ <input type="text" name="service_expired_date_end" id="service_expired_date_end" style="width: 100px">
<br />
关键字：<input type="text" name="keyword" <?php if($this->keyword){echo "value='".$this->keyword."'";}?> />
&nbsp;&nbsp;&nbsp;&nbsp;
<input type="submit" class="button" value="搜索" />
&nbsp;&nbsp;&nbsp;&nbsp;
<input type="button" class="button-cancle" value="清空搜索条件" onclick="location.href='?';" />
&nbsp;&nbsp;&nbsp;&nbsp;
<font color="red"><b>当前搜索结果: 合同数 <?=$this->data['ct']?></b></font>
</form>
<br />
<table style="width: 2000px">
  <tr>
    <th>合同编号</th>
    <th>产品</th>
    <th>签约服务</th>
    <th>销售</th>
    <th>服务时间</th>
    <th>经销商</th>
    <th>渠道</th>
    <th>合同金额</th>
    <th>回款性质</th>
    <th>应收</th>
    <th>已收</th>
	<?php if(!empty($this->stat)):?>
	<?php foreach($this->stat['col_title'] as $key => $val):?>
	<th><?=$val?></th>
	<?php endforeach;?>
	<?php endif;?>
  </tr>
  <?php $data = $this->data['current_page_info'];?>
  <?php if($data["dealer_company_name"]):?>
  <?php foreach($data["dealer_company_name"] as $id => $something):?>
  <tr>
    <td><?=$data["contract_sid"][$id]?></td>
    <td><?=$data["product_name"][$id]?></td>
    <td><?=$data["service_info"][$id]?></td>
	<td><?=$data["sales_emp_name"][$id]?></td>
    <td><?=$data["service_start_date"][$id]?><br><?=$data["service_expired_date"][$id]?></td>
	<td><?=$data["province_name"][$id]?>&nbsp;<?=$data["city_name"][$id]?>&nbsp;<?php if(1==$data["dealer_type"][$id]){echo "【4S】";}elseif(2==$data["dealer_type"][$id]){echo "【展厅】";}elseif(3==$data["dealer_type"][$id]){echo "【综合店】";}?><br><?=$data["dealer_company_name"][$id]?></td>
    <td><?=$data["channel_info"][$id]?></td>
    <td><?=number_format($data["contract_value"][$id], 0, ".", ",")?></td>
    <td><?php if(1==$data["received_type"][$id]){echo "100%";}elseif(2==$data["received_type"][$id]){echo "60%";}elseif(3==$data["received_type"][$id]){echo "返点";}?></td>
	<td><?=number_format($data["receivable_value"][$id], 0, ".", ",")?></td>
    <td><?=number_format($data["received_value"][$id], 0, ".", ",")?></td>
	<?php if(!empty($this->stat)):?>
	<?php foreach($this->stat['col_title'] as $key => $val):?>
	<td>-</td>
	<?php endforeach;?>
	<?php endif;?>
  </tr>
  <?php endforeach;?>
  <?php endif;?>
</table>

<br /><br /><br />

<script>
$(function() {
	$( "#contract_start_date_start" ).datepicker({ dateFormat: 'yy-mm-dd'});
});
$(function() {
	$( "#contract_start_date_end" ).datepicker({ dateFormat: 'yy-mm-dd'});
});
$(function() {
	$( "#contract_expired_date_start" ).datepicker({ dateFormat: 'yy-mm-dd'});
});
$(function() {
	$( "#contract_expired_date_end" ).datepicker({ dateFormat: 'yy-mm-dd'});
});
$(function() {
	$( "#service_start_date_start" ).datepicker({ dateFormat: 'yy-mm-dd'});
});
$(function() {
	$( "#service_start_date_end" ).datepicker({ dateFormat: 'yy-mm-dd'});
});
$(function() {
	$( "#service_expired_date_start" ).datepicker({ dateFormat: 'yy-mm-dd'});
});
$(function() {
	$( "#service_expired_date_end" ).datepicker({ dateFormat: 'yy-mm-dd'});
});

function GetCities(provinceId)
{
	$.ajax({
			type: "post",
			url : "/ajax/get-cities",
			dataType:'json',
            async:false,
			data: {
					'provinceId':provinceId
				  },
				success: function(json){
					if(json.result == 1 && typeof(json.data) != "undefined") {
                        var arr = json.data;
						var txt = "<option value=''>不限</option>";
						
                        for(i=0; i < arr.length; i++){
							txt += "<option value='" + arr[i]['cityId'] + "'>" + arr[i]['cityName'] + "</option>";
                        }
						
						document.getElementById("city_id").innerHTML = txt;
                    }
			}
		});
}

function ContractOpt(id, status)
{
	$.ajax({
			type: "post",
			url : "/ajax/contract-opt",
			dataType:'json',
            async:false,
			data: {
					'id':id,
					'status':status
				  },
				success: function(json){
					if(json.result == 1) {
                        window.location.href = "/contracts/index/msg/2";
                    }else{
						window.location.href = "/contracts/index/msg/3";
					}
			}
		});
}
</script>